package top.forforever.srb.core.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.forforever.srb.common.result.R;
import top.forforever.srb.core.pojo.entity.Borrower;
import top.forforever.srb.core.pojo.vo.BorrowerApprovalVO;
import top.forforever.srb.core.pojo.vo.BorrowerDetailVO;
import top.forforever.srb.core.service.BorrowerService;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Mr.Jiang
 * @since 2023-04-29
 */
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

    @Autowired
    private BorrowerService borrowerService;

    @GetMapping("list/{page}/{limit}")
    public R getPageList(@PathVariable Integer page,@PathVariable Integer limit,
                         @RequestParam("keyword") String keyword) {
        IPage<Borrower> pageModel = borrowerService.getPageList(page,limit,keyword);
        return R.ok().data("pageModel",pageModel);
    }

    @GetMapping("detail/{borrowerId}")
    public R detail(@PathVariable Long borrowerId) {
        BorrowerDetailVO borrowerDetailVO = borrowerService.detailByBorrowerId(borrowerId);
        return R.ok().data("borrowerDetail",borrowerDetailVO);
    }

    @PostMapping("approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO) {
        borrowerService.approval(borrowerApprovalVO);
        return R.ok().message("审核通过");
    }

}

